Using scripts

Use JavaScript scripts to program the logic and look of your application right in Kanzi Studio.

In your Kanzi Studio project scripts are stored in the Library > Resource Files > Scripts, and on the hard drive in the <ProjectName>/Scripts directory.

Note that when you change a node using a script, you change it in Kanzi Engine, which means that the changed state is not synchronized in Kanzi Studio. For example, if you use a script to disable the visibility of a node, that node is not visible in the Preview, but the node's Visible property still appears in the Properties as enabled.

See Scripting reference.

Adding a JavaScript script

To add a JavaScript script to a node:

  1. Create a node from which you want to trigger the script and add a trigger to it. See Adding a trigger.
    For example, create a Button 3D and use the Button: Click trigger.
  2. In the Node Components > Triggers section in the trigger you want to use to execute a script, click the Add dropdown menu, and select the Execute Script action.
    The Execute Script window opens.
  3. In the Execute Script window select an existing script, or select + Create Script to create a new script.
    The Script Editor window opens.
  4. In the Script Editor write the script you want to execute. See Scripting reference.
    For example, write this line to print Hello Kanzi! to the Log window.
    print('Hello Kanzi');
  5. When you are done writing the script, in the Script Editor click Save.
  6. Set off the trigger to execute the script.
    For example, if you created a button and used the Button: Click trigger, click that button.

Accessing nodes and properties from a script

You can access nodes and properties from a script either by typing their location and name, or by dragging and dropping to the Script Editor the item you want to add to a script.

To add a node or a property to a JavaScript script:

  1. Open or create a script to which you want to add a property or a property and place the cursor to the position where you want to add it.
  2. From the Project drag the node or from the Properties drag the property you want to add to the script and drop it to the Script Editor.

See also

Scripting reference